package com.shuoyue.ycgk.ui.main.today_count;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.google.android.material.tabs.TabLayout;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.base.BaseMvpFragment;
import com.shuoyue.ycgk.base.baseadapter.IndexFragmentStateAdapter;
import com.shuoyue.ycgk.ui.mine.order.FragmentOrder;
import com.shuoyue.ycgk.views.viewpager_scroll.SuperViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TodayActivity extends BaseMvpActivity {

    int moduleId;
    int index;

    public static void start(Context context, int moduleId, int index) {
        context.startActivity(new Intent(context, TodayActivity.class)
                .putExtra("moduleId", moduleId)
                .putExtra("index", index)

        );
    }

    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R.id.view_pager)
    SuperViewPager viewPager;

    protected IndexFragmentStateAdapter indexFragmentAdapter;
    protected List<BaseMvpFragment> fragmentMainItems;



    /**
     * 初始化layouy
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_simple_tab_viewpager;
    }

    @Override
    protected void initView() {
        pageTitle.setText("今日学习");
        moduleId = getIntent().getIntExtra("moduleId", -1);
        index = getIntent().getIntExtra("index", 0);

        fragmentMainItems = new ArrayList<>();
        fragmentMainItems.add(FragmentTodayQuestion.getInstance(moduleId));
        fragmentMainItems.add(FragmentTodayCourse.getInstance(moduleId));

        indexFragmentAdapter = new IndexFragmentStateAdapter(getSupportFragmentManager(), fragmentMainItems);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setOffscreenPageLimit(1);
        viewPager.setAdapter(indexFragmentAdapter);
        viewPager.setCurrentItem(index);
    }

    @Override
    public void initData() {
        super.initData();
    }

    @OnClick(R.id.back)
    public void onClick() {
        finish();
    }
}
